<?php
$isReloadable = false;
require_once("../../pers/inc.config.php");
require_once(R2_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(R2_FS_WEB_ROOT.'/app/_inc/funct.html.php');
$aFlagUte = array();
require "../uten/_inc/inc.aFlagUte.php";

//Gestione azioni
if (reqvar('azione')=='salva'){
	$msgPag .= salva($aFlagUte);
}

$sSql = "SELECT * FROM utente WHERE id_utente = ".$objSess->idUtente;
$objDB->exec($sSql);
$aRec = $objDB->fetch();
if (!$aRec) {
	backOnErr("id '".reqVar('id')."' inesistente !");
	exit;
}
reqDef('login',$aRec['login']);
reqDef('nome',$aRec['nome']);
reqDef('e_mail',$aRec['e_mail']);
reqDef('ric_ope',$aRec['ric_ope']);
reqDef('password','');
reqDef('password2','');

$sCmdL = "";
$sCmdR = "";

if ($objSess->abilitaz['gescomm'] == 'W') {
	$sCmdR .= "<a class='cmd1' href='javascript:document.frm1.submit();' >salva</a>";
}	
$sCmdR .= cmdTorna('torna');

$aMenuPag = array();
include("../_inc/inc.aMenuPag.php");
testaHtml('Cambio password', $msgPag, '30.10.10', $aMenuPag);
echo getHtmlForm();
echo getHtmlHidden('id');
echo getHtmlHidden('xsn');
echo getHtmlHidden('azione','salva');
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='top'><?=$sCmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdR?></td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
<?php echo getHtmlRigaRif();?>
	<tr>
		<td class="tit1" colspan='20' align='center'>Utente</td>
	</tr>
    <tr>
   	<td class="lab1" colspan='2'>Login</td>
	  	<td class="txt1" colspan='6'><?echo reqVar('login');?></td>
   	<td class="lab1" colspan='2'>Nome</td>
	  	<td class="txt1" colspan='10'><?echo reqVar('nome');?></td>
    </tr>
    <tr>
   	<td class="lab1" colspan='2'>Tipo utente</td>
	  	<td class="txt1" colspan='6'>
	  		<?
	  		if (reqVar('ric_ope')=='ope')	echo 'Operatore';
	  		else echo 'Richiedente';
	  		?>
	  	</td>
   	<td class="lab1" colspan='2'>E-mail</td>
	  	<td class="txt1" colspan='10'><?echo reqVar('e_mail');?></td>
    </tr>
    <tr>
   	<td class="lab1" colspan='2'>Password</td>
	  	<td class="txt1" colspan='6'><?echo getHtmlText('password',30);?></td>
   	<td class="lab1" colspan='2'>Ridigita password</td>
	  	<td class="txt1" colspan='10'><?echo getHtmlText('password2', 30);?></td>
    </tr>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='top'><?=$sCmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdR?></td>
   </tr>
</table>
<?
codaHtml();
exit();

function salva($aFlagUte) {
	global $objDB, $objSess;

	$msg = '';
	if (reqVar('password')=='') {
		$msg .= "manca password <br>";
	}
	if (preg_match("/ /",reqVar('password'))) {
		$msg .= "password non deve contenere spazi<br>";
	}
	if (reqVar('password')!=reqVarTrim('password2')) {
		$msg .= "password ridigitata errata<br>";
	}
	
	if ($msg != '') {return $msg;}
	
	$sSql = "UPDATE utente SET password = '".reqvarAS('password')."' ";
	$sSql .= " WHERE id_utente = ".$objSess->idUtente;
	$objDB->query($sSql);
	header("Location: ".urlTorna('password modificata'));
	exit();
}

?>